float4x4 World;
float4x4 View;
float4x4 Projection;

float minLength;
float speed;
float thickness;
float intensity;
float age;
float4 edgeColor;
float4 interiorColor;
float LaserOffsetX;
float LaserOffsetZ;

texture Texture;
sampler Sampler = sampler_state
{
    Texture = (Texture);  
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VertexShaderInput
{
    float4 Position : POSITION0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
    
    float4 pos = input.Position;
    float index = pos.w;
    pos.x -= 0.5f;
	pos.x *= thickness;
	pos.x += LaserOffsetX*thickness;
	pos.z += LaserOffsetZ;
    pos.z *= -(minLength + speed*age);

    pos.y = 1.0f;
    pos.w = 1.0f;

    float4 worldPosition = mul(pos, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    output.Texcoord = input.Position.xz;

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    //return tex2D(Sampler, input.Texcoord);
	float xdist = 2.0*abs(input.Texcoord.x-0.5);
	float4 color;
	float low_bound = 0.01;
	float hi_bound = 0.9;
	float xmult = 1.0;
	if(input.Texcoord.y < low_bound)
	{
		float t = input.Texcoord.y/low_bound;
		xmult = t*t*t;	
	}
	else if(input.Texcoord.y > hi_bound)
	{
		float t = (input.Texcoord.y - hi_bound)/(1.0 - hi_bound);
		#define MyPI 3.1415926535897932384626433832795
		xmult = cos(MyPI*0.5*t);
	}
	xdist = 1.0 - xdist;
	color.rgba = lerp(edgeColor,interiorColor,xmult*xdist);
	color.a *= color.a;
	color.a *= color.a;
	
    return color;
}

technique Tech
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
